﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HystereticBasic
{
    /// <summary>
    /// 基于Park的延性系数
    /// </summary>
    public class DuctilityPark : DuctilityBasic
    {
        /// <summary>
        /// PARK洗漱
        /// </summary>
        private float ParkFactor { set; get; }

        /// <summary>
        /// 设定屈服点
        /// </summary>
        /// <returns></returns>
        public override bool SetYieldPt()
        {
            //初始化
            this.initialForYield();
            //数据点过少
            if (this.SkeletonObj.Count < 2) return false;
            //零点
            var zeroPt = new ForceDispBasicPair();
            //初始化点A
            ForceDispBasicPair ptA, ptB, ptC;
            //力限值
            var forceLimit = Math.Abs(this.Mu * this.ParkFactor);
            //获得骨架上升段
            var prePeakSkeleton = this.SkeletonObj.PrePeakSkeleton;
            //A 点：曲线与 Y=M park 的交点
            if (!prePeakSkeleton.GetPtByForce(forceLimit, out ptA)) return false;
            //B 点：OA与 Y=Mu 的交点
            if (!zeroPt.GetInterpolationPt(ptA, this.Mu, out ptB)) return false;
            //c 点：曲线与 X=DB 的交点
            if (!prePeakSkeleton.GetPtByDisp(ptB.Disp, out ptC)) return false;
            //获得等效屈服点
            this.YiledPoint = ptC;
            //获得过程点
            this.DuctilityFDObj.Add(ptA);
            this.DuctilityFDObj.Add(ptB);
            this.DuctilityFDObj.Add(ptC);
            //添加屈服点
            this.LineYList.Add(ptA);
            this.LineYList.Add(this.YiledPoint);
            return true;
        }

        /// <summary>
        /// 延性计算方法
        /// </summary>
        /// <returns></returns>
        public override DuctilityMethod GetMethod()
        {
            return DuctilityMethod.Park;
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="skeletonObj"></param>
        /// <param name="ultimateStrengthFactor"></param>
        /// <param name="parkFactor"></param>
        public DuctilityPark(MontForceDispObj skeletonObj, ForceDispBasicPair ultimatePoint, float parkFactor)
            : base(skeletonObj, ultimatePoint)
        {
            this.ParkFactor = parkFactor;
        }
    }
}
